/*
 * @Author: xiawei 1243162387@qq.com
 * @Date: 2024-04-29 17:18:42
 * @LastEditors: xiawei 1243162387@qq.com
 * @LastEditTime: 2024-05-07 17:59:19
 */
import type Node from 'element-plus/es/components/tree/src/model/node'
import { ref } from 'vue'
const useTree = () => {
  // tree实例
  const VCTreeRef = ref()
  // 远程加载数据
  const remoteLoadData = (node: Node) => {
    let id = node.data?.id;
    return new Promise((_resolve, _reject) => {
      setTimeout(() => {
        _resolve([
          {
            label: 'Level one 1',
            id: !id ? '1' : `${id}_1`
          },
          {
            label: 'Level one 2',
            id: !id ? '2' : `${id}_2`,
          },
          {
            label: 'Level one 3',
            id: !id ? '3' : `${id}_3`,
          },
        ])
      }, 300)
    })
  }

  const nodeClick = (data: any)=>{
    console.log(data)
  }
  const check = (data: any,treeSelected: any)=>{
    console.log(data)
    console.log(treeSelected)
  }
  return {
    VCTreeRef,
    remoteLoadData,
    nodeClick,
    check
  }
}
export default useTree